/*
 * Created on Jan 16, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.scohen.juploadr.ui;

import java.util.LinkedList;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.scohen.juploadr.Messages;
import org.scohen.juploadr.app.JUploadr;

/**
 * @author steve
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class TrayPopupHandler extends PopupHandler {
    private static final String OPTION_SHOW = Messages
            .getString("juploadr.ui.label.show"); //$NON-NLS-1$
    private static final String OPTION_HIDE = Messages
            .getString("juploadr.ui.label.hide"); //$NON-NLS-1$
    private static final String OPTION_QUIT = Messages
            .getString("juploadr.ui.label.exit"); //$NON-NLS-1$

    private JUploadr uploader;

    public TrayPopupHandler(Shell parent, JUploadr uploadr) {
        super(parent);
        this.parent = parent;
        this.uploader = uploadr;
        show();
    }

    public void widgetSelected(SelectionEvent event) {
        MenuItem src = (MenuItem) event.widget;
        String action = src.getText();
        if (action.equals(OPTION_QUIT)) {
            uploader.quit();
        } else if (action.equals(OPTION_HIDE)) {
            parent.setVisible(false);
        } else if (action.equals(OPTION_SHOW)) {
            parent.setVisible(true);
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.scohen.juploadr.ui.PopupHandler#regenerateOptions()
     */
    protected void regenerateOptions() {
        options = new LinkedList<PopupData>();
        if (parent.isVisible()) {
            options.add(new PopupData(OPTION_SHOW, false));
            options.add(new PopupData(OPTION_HIDE, true));
        } else {
            options.add(new PopupData(OPTION_SHOW, true));
            options.add(new PopupData(OPTION_HIDE, false));
        }
        options.add(PopupData.SEPARATOR);
        options.add(new PopupData(OPTION_QUIT, true));

    }

}